Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

314
Views
status: 400 title: "One or more validation errors occurred."

I am currently getting the 400 error code and I don't quite understand what is wrong. I have tried to search for answers online but none of the results are doing much help. Any help/insight would be greatly appreciated. Thank you.

The JSON value could not be converted to TheMoonshineCafe.Models.Event. Path: $ | LineNumber: 0 | BytePositionInLine: 1.

It seems maybe the payload is not being converted into the Event type properly?

Edit event function from my data service:

  editEvent(id: Number, event: EventWithID[]){
    var callResult : any;
    console.log(id);
    console.log(event);
    this.http.put(this.baseUrl + 'api/Events/' + id, event).subscribe(result => {
      callResult = result;
      console.log(result);
    })
  }

Put Event from my API:

[HttpPut("{id}")]
        public async Task<ActionResult<Event>> PutEvent(int id, Event @event)
        {
            if (id != @event.id)
            {
                return BadRequest();
            }

            _context.Entry(@event).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EventExists(id))
                {
                    return NotFound();
                }
                else
                {
                    throw;
                }
            }

            return NoContent();
        }

payload:

export class EventWithID {
    id: number;
    eventStart: Date;
    eventEnd: Date;
    refundCutOffDate: Date;
    bandName: String;
    bandImagePath: String;
    bandLink: String;
    maxNumberOfSeats: number;
    currentNumberOfSeats: number;
    ticketPrice: number;
    description: String;
  }

Models.Event:

public class Event
    {
        public int id {get; set; }
        public DateTime eventStart { get; set; }
        public DateTime eventEnd { get; set; }
        public DateTime refundCutOffDate { get; set; }
        public string bandName { get; set; }
        public string bandImagePath { get; set; }
        public string bandLink { get; set; }
        public int maxNumberOfSeats { get; set; }
        public int currentNumberOfSeats { get; set; }
        public double ticketPrice { get; set; }
        public string description { get; set; }
    }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

fix the action

    public async Task<ActionResult<Event>> PutEvent(Event model)
   {
if(model.Id==0) return BadRequest("Wrong Id");
var existedEvent= await _context.Set<Event>().FirstOrDefaultAsync(i=> i.Id==model.Id);

            if (existedEvent==null ) return BadRequest("Record not found");

            _context.Entry(existedEvent).CurrentValues.SetValues(model);

          try
            {
                await _context.SaveChangesAsync();
            }
            ......

and javascript

  this.http.put(this.baseUrl + 'api/Events', event).subscribe(result => {
 ....

and instead of put I highly recommend to use post.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!